home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / modeler / martianplumber.lwm < prev    next >
Text File  |  1993-12-13  |  6KB  |  259 lines

  1. /* CMD: Weird Tubes
  2.  * Use the Martian Plumber to create strange tubes and connectors.. Nurnies!?
  3.  * This script was inspired by Ron Thorton of B5 fame, who uses weird things
  4.  * like this to adorn otherwise boring surfaces on space ships and such.
  5.  * Please add more modes and tricks to this, and send it back to me!!
  6.  * as an exersize for the reader: add a random twist to the tubes,
  7.  *   Lathe random curves into tubes, add cool connector types,
  8.  *  By Arnie Cachelin © 1993 NewTek Inc. */
  9.  
  10. ax.1='X'
  11. ax.2='Y'
  12. ax.3='Z'
  13. call addlib "LWModelerARexx.port", 0
  14. signal on error
  15. signal on syntax
  16. sysnam = 'Weird Tubes'
  17. version = '1.0'
  18.  
  19. call req_begin sysnam
  20.  
  21. id_num = req_addcontrol("Segments", 'N')
  22. id_len = req_addcontrol("Segment Length", 'N')
  23. id_ind = req_addcontrol("Axis", "CH",'X Y Z Random')
  24. id_cnt = req_addcontrol("Center", 'V', 0)
  25.  
  26. call req_setval id_num 1,1
  27. call req_setval id_len 5,5
  28. call req_setval id_cnt 0,0,0
  29.  
  30. if (~req_post()) then do
  31.     call req_end
  32.     exit
  33. end
  34.  
  35. rand=1
  36. TubeTypes=4
  37. ConnectTypes=3
  38. cen = req_getval(id_cnt)
  39. parse var cen cx cy cz
  40. /* cen= cx', 'cy', 'cz */
  41. ax = req_getval(id_ind)
  42. if ax=4 then ax =random(1,3,time('s'))
  43. else rand=0
  44. num = req_getval(id_num)
  45. maxlen = req_getval(id_len)
  46. call req_end
  47.  
  48. xrad=random(1,2,time('s')) /* Just a seed */
  49. xrad=0.05*maxlen*(1+randu())
  50. do tube=1 to num
  51.   typ=random(1,TubeTypes,time('S'))
  52.   len=0.5*maxlen*(1+randu())
  53.   rad=0.05*maxlen*(1+randu())
  54.   r=max(rad, xrad)
  55.   xrad=rad
  56.   ctyp=random(1,ConnectTypes,time('S'))
  57.   call SURFACE("Connector"||ctyp)
  58.   select
  59.     when ctyp=1 then do
  60.       call MAKEBALL(r,16,8,cen)
  61.       end
  62.     when ctyp=2 then do
  63.       call MAKEBOX(cx-r cy-r cz-r,cx+r cy+r cz+r,1)
  64.       end
  65.     when ctyp=3 then do
  66.       cax=random(1,3,time('S'))
  67.       t.1=cx
  68.       t.2=cy
  69.       t.3=cz
  70.       call MAKEDISC(r,t.cax-r,t.cax+r,Ax.cax,random(5,10,time(S)),1,cen)
  71.       end
  72.     end
  73.   if ax=1 then do
  74.     call MOVE(len 0 0)
  75.     end
  76.   if ax=2 then do
  77.     call MOVE(0 len 0)
  78.     end
  79.   if ax=3 then do
  80.     call MOVE(0 0 len)
  81.     end
  82.   call maketube(cen,len,rad,ax,typ)
  83.   cen= cx' 'cy' 'cz
  84.   if rand then ax=random(1,3,time('S'))
  85.   end
  86. exit
  87.  
  88. syntax:
  89. error:
  90.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  91.     exit
  92.  
  93. MakeTube: PROCEDURE
  94.   arg cen, len, rad, ax,t
  95.   parse var cen cx' 'cy' 'cz
  96.   axlet=translate(ax,'XYZ','123')
  97.   call SURFACE("TubeType_"||t)
  98.   tb.1=cx
  99.   tb.2=cy
  100.   tb.3=cz
  101.   select
  102.     when t=1 then do
  103.       sides=random(3,16,time('s')) /* Rand Tube */
  104.       mrad=max(randu(),0.5)*rad
  105.       r.1=rad' 'rad' 'mrad
  106.       r.2=rad' 'rad' 'mrad
  107.       r.3=rad' 'mrad' 'rad
  108.       call MAKEDISC(r.ax, tb.ax,tb.ax+len,axlet,sides,1,cen)
  109.       end
  110.     when t=2 then do
  111.       sides=12 /* Tri-Tube */
  112.       cn.1=cx' 'cy+rad*.5' 'cz
  113.       cn.2=cx+rad*.5' 'cy' 'cz
  114.       cn.3=cx' 'cy+rad*.5' 'cz
  115.       call CUT()
  116.       call MAKEDISC(0.5*rad,tb.zx,tb.ax+len,axlet,sides,1,cn.ax)
  117.       call ROTATE(120,axlet,cx cy cz)
  118.       call MAKEDISC(0.5*rad,tb.zx,tb.ax+len,axlet,sides,1,cn.ax)
  119.       call ROTATE(120,axlet,cx cy cz)
  120.       call MAKEDISC(0.5*rad,tb.zx,tb.ax+len,axlet,sides,1,cn.ax)
  121.       call PASTE()
  122.       end
  123.     when t=3 then do
  124.       r=0.707*rad
  125.       lcorn.1=cx' 'cy+r' 'cz+r
  126.       hcorn.1=cx+len' 'cy-r' 'cz-r
  127.       lcorn.2=cx+r' 'cy' 'cz+r
  128.       hcorn.2=cx-r' 'cy+len' 'cz-r
  129.       lcorn.3=cx+r' 'cy+r' 'cz
  130.       hcorn.3=cx-r' 'cy-r' 'cz+len
  131.       caLL MAKEBOX(lcorn.ax,hcorn.ax,1)
  132.       if random(0,1,time('s')) then call ROTATE(45,axlet,cen)
  133.       end
  134.     when t=4 then do  /* Accordion tube */
  135.       if ax="1" then do
  136.         y1=cy+rad
  137.         y2=cy+rad*(0.5*randu() + 0.25)
  138.         segs=random(2,5,time('s'))
  139.         dx=len/(2*segs)
  140.         x=cx
  141.         p=0
  142.         call CUT()
  143.         call add_begin
  144.         do i=1 to segs
  145.           vec= x y1 cz
  146.           call add_point vec
  147.           p=p+1
  148.           x=x+dx
  149.           call add_point x y2 cz
  150.           p=p+1
  151.           x=x+dx
  152.           call add_polygon p-1 p
  153.           call add_point x y1 cz
  154.           p=p+1
  155.           call add_polygon p-1 p
  156.           end
  157.         call add_end
  158.         call LATHE(axlet,random(3,16),cx cy cz)
  159.         call PASTE()
  160.         end
  161.       if ax="2" then do
  162.         x1=cx+rad
  163.         x2=cx+rad*(0.5*randu() + 0.25)
  164.         segs=random(2,5,time('s'))
  165.         dy=len/(2*segs)
  166.         y=cy
  167.         p=0
  168.         call CUT()
  169.         call add_begin
  170.         do i=1 to segs
  171.           call add_point x1 y cz
  172.           p=p+1
  173.           y=y+dy
  174.           call add_point x2 y cz
  175.           p=p+1
  176.           y=y+dy
  177.           call add_polygon p-1 p
  178.           call add_point x1 y cz
  179.           y=y+dy
  180.           p=p+1
  181.           call add_polygon p-1 p
  182.           end
  183.         call add_end
  184.         call LATHE(axlet,random(3,16),cx cy cz)
  185.         call PASTE()
  186.         end
  187.       if ax="3" then do
  188.         y1=cy+rad
  189.         y2=cy+rad*(0.5*randu() + 0.25)
  190.         segs=random(2,5,time('s'))
  191.         dz=len/(2*segs)
  192.         z=cz
  193.         p=0
  194.         call CUT()
  195.         call add_begin
  196.         do i=1 to segs
  197.           call add_point cx y1 z
  198.           p=p+1
  199.           z=z+dz
  200.           call add_point cx y2 z
  201.           p=p+1
  202.           z=z+dz
  203.           call add_polygon p-1 p
  204.           call add_point cx y1 z
  205.           z=z+dz
  206.           p=p+1
  207.           call add_polygon p-1 p
  208.           end
  209.         call add_end
  210.         call LATHE(axlet,random(3,16),cx cy cz)
  211.         call PASTE()
  212.         end
  213.       end
  214.     end
  215.     return t
  216.  
  217.  
  218. Transform:   /* Replace with a single new call */
  219.   arg mov, rot, scl, cnt
  220.   parse var rot rx','ry','rz
  221.   call SCALE(scl,cnt)
  222.   if rx~=0 then call ROTATE(rx,'X',cnt)
  223.   if ry~=0 then call ROTATE(ry,'Y',cnt)
  224.   if rz~=0 then call ROTATE(rz,'Z',cnt)
  225.   call MOVE(mov)
  226.   return
  227.  
  228. BevelText: Procedure /* Have flat text polygons ready! */
  229.   call BEVEL(0.015,0.015)
  230.   call COPY()
  231.   call UNDO()
  232.   call EXTRUDE('Z',0.1,1)
  233.   call PASTE()
  234.   return
  235.  
  236. Center: Procedure
  237.   box=boundingbox()  /* Should check out empty list ...  */
  238.   parse var box n x1 x2 y1 y2 z1 z2
  239.   cx=-(x2+x1)/2
  240.   cy=-(y2+y1)/2
  241.   cz=-(z2+z1)/2
  242.   call MOVE(cx cy cz)
  243.   return box
  244.  
  245. CenterAx: Procedure
  246.   arg A
  247.   box=boundingbox()  /* Should check out empty list ...  */
  248.   parse var box n x1 x2 y1 y2 z1 z2
  249.   cx=-(x2+x1)/2
  250.   cy=-(y2+y1)/2
  251.   cz=-(z2+z1)/2
  252.   say A cx cy cz
  253.   if ~pos(upper(A),'X') then cx=0
  254.   if ~pos(upper(A),'Y') then cy=0
  255.   if ~pos(upper(A),'Z') then cz=0
  256.   say cx cy cz
  257.   call MOVE(cx cy cz)
  258.   return box
  259.